package com.xin.ruanjian.omsystem.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xin.ruanjian.omsystem.R;
import com.xin.ruanjian.omsystem.view.TimeSelectDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by local123 on 2018/3/3.
 */

public class TimeSelectRightAdapter extends RecyclerView.Adapter<TimeSelectRightAdapter.ViewHolder> {
    private Context context;
    private int select = 0;
    private List<String> mData;
    private onItemClickLitener litener;

    public TimeSelectRightAdapter(Context context, List<String> data) {
        this.context = context;
        mData = data;
    }

    public void setLitener(onItemClickLitener litener) {
        this.litener = litener;
    }

    @Override
    public TimeSelectRightAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_rv_dialog_time_select_right, parent, false);
        return new TimeSelectRightAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TimeSelectRightAdapter.ViewHolder holder, final int position) {
        holder.tvTime.setText(mData.get(position));
        holder.tvTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (litener != null) {
                    select = position;
                    litener.onItemOnClick(mData.get(position));
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        if (mData != null) {
            return mData.size();
        }
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_time)
        TextView tvTime;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface onItemClickLitener {
        void onItemOnClick(String time);
    }
}
